<?xml version='1.0' encoding='UTF-8' ?>
<!DOCTYPE composition PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<ui:composition xmlns:ui="http://java.sun.com/jsf/facelets"
                template="./../template/AdminTemplate.xhtml"
                xmlns:h="http://java.sun.com/jsf/html"
                xmlns:p="http://primefaces.org/ui"
                xmlns:f="http://java.sun.com/jsf/core">

    <ui:define name="title">
        Currency management
    </ui:define>

    <ui:define name="content">
        <p:growl id="growl1" showDetail="true" life="3000" /> 
        <h:form id="form">

            <h:panelGrid columns="1">

                <h:panelGrid columns="1">

                    <p:dataTable var="curvar" value="#{currencyMBean.currencyList}" rowKey="#{curvar.currencyID}" paginator="true" rows="10"
                                 selection="#{currencyMBean.currency}" selectionMode="single" filteredValue="#{currencyMBean.filteredCurrency}" id="currencyTable" 
                                 paginatorTemplate="{PreviousPageLink} {CurrentPageReport} {NextPageLink} {RowsPerPageDropdown}"
                                 rowsPerPageTemplate="5,10,15">

                        <p:ajax event="rowSelect" update=":form:display" oncomplete="currencyDialog.show()" />

                        <f:facet name="header">
                            List of Currency
                        </f:facet>

                        <p:column headerText="CurrencyID" sortBy="#{curvar.currencyID}" filterBy="#{curvar.currencyID}" id="currencyID">
                            #{curvar.currencyID}
                        </p:column>

                        <p:column headerText=" Types of Currency" sortBy="#{curvar.currencyName}" filterBy="#{curvar.currencyName}" id="currencyName">
                            #{curvar.currencyName}
                        </p:column>

                        <p:column headerText="VND Rate" sortBy="#{curvar.VNDRate}" filterBy="#{curvar.VNDRate}" id="VNDRate">
                            #{curvar.VNDRate}
                        </p:column>

                    </p:dataTable>



                    <p:dialog header="Currency Detail" widgetVar="currencyDialog" resizable="true"  
                              width="380" showEffect="explode" hideEffect="explode">

                        <h:panelGrid id="display" columns="2" cellpadding="4">

                            <f:facet name="header">
                                <h:outputText value="Hinh anh" />
                            </f:facet>

                            <h:outputText value="CurrencyID " />
                            <h:inputText value="#{currencyMBean.currency.currencyID}" id="currencyID"/>                        

                            <h:outputText value="Types of currency" />
                            <h:inputText value="#{currencyMBean.currency.currencyName}" id="currencyName"/>

                            <h:outputText value="VND Rate" />
                            <h:inputText value="#{currencyMBean.currency.VNDRate}" id="VNDRate"/>

                            <p:commandButton value="Delete" action="#{currencyMBean.removeCurrency()}" oncomplete="currencyDialog.hide()" update=":form:currencyTable, :growl1"/>
                            <p:commandButton value="Update" action="#{currencyMBean.editCurrency(currencyMBean.currency)}" oncomplete="currencyDialog.hide()" update=":form:currencyTable, :growl1"/>

                        </h:panelGrid>
                    </p:dialog>    

                </h:panelGrid>

            </h:panelGrid>

        </h:form>
        <h:form>
            <h:panelGrid columns="1">

                    <p:commandButton id="viewButton" value="Add type of Currency" 
                                     oncomplete="addCurrrencyDialog.show()"/> 

                    <p:dialog id="dialogadd" header="Add New Type of Currency" widgetVar="addCurrrencyDialog" resizable="false"  
                              showEffect="fade" hideEffect="fade">  
                        <h:panelGrid id="displayAdd" columns="3" cellpadding="4">  

                            <p:outputLabel value="Types of currency:" for="curName"/>
                            <p:inputText id="curName" value="#{currencyMBean.other.currencyName}" title="Types of currency" required="true" />                    
                            <p:message for="curName"/>

                            <p:outputLabel value="VND Rate:" for="rate"/>
                            <p:inputText id="rate" value="#{currencyMBean.other.VNDRate}" title="VND Rate" required="true" />                    
                            <p:message for="rate"/>
                        </h:panelGrid>  
                        <p:commandButton value="Create" action="#{currencyMBean.createCurrency()}" oncomplete="addCurrrencyDialog.hide()" update=":growl1, :form:currencyTable"/>                      
                    </p:dialog>

                </h:panelGrid>
        </h:form>
    </ui:define>

</ui:composition>
